if not exists(select * from sysdatabases where name='xxl_job')
begin
	create database xxl_job
end
go
use xxl_job
go
-- ----------------------------
-- Table structure for xxl_job_group
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_group]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_group]
    go

CREATE TABLE [dbo].[xxl_job_group] (
    [id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
    [app_name] varchar(64)  NOT NULL,
    [title] varchar(12)  NOT NULL,
    [address_type] int  NOT NULL DEFAULT '0',
    [address_list] varchar(max)  ,
    [update_time] datetime  NULL
    )
    go

    -- ----------------------------
-- Table structure for xxl_job_info
-- ----------------------------
    IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_info]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_info]
    go

CREATE TABLE [dbo].[xxl_job_info] (
    [id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
    [job_group] int  NOT NULL,
    [job_desc] varchar(255)    NOT NULL,
    [add_time] datetime  NULL,
    [update_time] datetime  NULL,
    [author] varchar(64)    NULL,
    [alarm_email] varchar(255)    NULL,
    [schedule_type] varchar(50)    NOT NULL DEFAULT 'NONE',
    [schedule_conf] varchar(128)    NULL,
    [misfire_strategy] varchar(50)    NOT NULL DEFAULT 'DO_NOTHING',
    [executor_route_strategy] varchar(50)    NULL,
    [executor_handler] varchar(255)    NULL,
    [executor_param] varchar(512)    NULL,
    [executor_block_strategy] varchar(50)    NULL,
    [executor_timeout] int  NOT NULL DEFAULT '0',
    [executor_fail_retry_count] int  NOT NULL DEFAULT '0',
    [glue_type] varchar(50)    NOT NULL,
    [glue_source] varchar(max)    NULL,
    [glue_remark] varchar(128)    NULL,
    [glue_updatetime] datetime  NULL,
    [child_jobid] varchar(255)   NULL,
    [trigger_status] int  NOT NULL DEFAULT '0',
    [trigger_last_time] bigint  NOT NULL DEFAULT '0',
    [trigger_next_time] bigint  NOT NULL DEFAULT '0'
    )
    go

    -- ----------------------------
-- Table structure for xxl_job_lock
-- ----------------------------
    IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_lock]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_lock]
    go

CREATE TABLE [dbo].[xxl_job_lock] (
    [lock_name] varchar(50)    NOT NULL PRIMARY KEY
    )
    go

    -- ----------------------------
-- Records of xxl_job_lock
-- ----------------------------
    INSERT INTO [dbo].[xxl_job_lock] ([lock_name]) VALUES ('schedule_lock')
    go

    -- ----------------------------
-- Table structure for xxl_job_log
-- ----------------------------
    IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_log]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_log]
    go

CREATE TABLE [dbo].[xxl_job_log] (
    [id] bigint IDENTITY(1,1) NOT NULL PRIMARY KEY ,
    [job_group] int  NOT NULL,
    [job_id] int  NOT NULL,
    [executor_address] varchar(255)    NULL,
    [executor_handler] varchar(255)    NULL,
    [executor_param] varchar(512)    NULL,
    [executor_sharding_param] varchar(20)    NULL,
    [executor_fail_retry_count] int  NOT NULL DEFAULT '0',
    [trigger_time] datetime  NULL,
    [trigger_code] int  NOT NULL,
    [trigger_msg] varchar(max)    NULL,
    [handle_time] datetime  NULL,
    [handle_code] int  NOT NULL,
    [handle_msg] varchar(max)    NULL,
    [alarm_status] int  NOT NULL DEFAULT '0'
    )
    go

-- ----------------------------
-- Table structure for xxl_job_log_report
-- ----------------------------
    IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_log_report]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_log_report]
    go

CREATE TABLE [dbo].[xxl_job_log_report] (
    [id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
    [trigger_day] datetime  NULL,
    [running_count] int  NOT NULL DEFAULT '0',
    [suc_count] int  NOT NULL DEFAULT '0',
    [fail_count] int  NOT NULL DEFAULT '0',
    [update_time] datetime  NULL
    )
    go


-- ----------------------------
-- Table structure for xxl_job_logglue
-- ----------------------------
    IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_logglue]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_logglue]
    go

CREATE TABLE [dbo].[xxl_job_logglue] (
    [id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
    [job_id] int  NOT NULL,
    [glue_type] varchar(50)    NULL,
    [glue_source] varchar(max)    NULL,
    [glue_remark] varchar(128)    NOT NULL,
    [add_time] datetime  NULL,
    [update_time] datetime  NULL
    )
    go

-- ----------------------------
-- Table structure for xxl_job_registry
-- ----------------------------
    IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_registry]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_registry]
    go

CREATE TABLE [dbo].[xxl_job_registry] (
    [id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
    [registry_group] varchar(50)    NOT NULL,
    [registry_key] varchar(255)    NOT NULL,
    [registry_value] varchar(255)    NOT NULL,
    [update_time] datetime  NULL
    )
    go


-- ----------------------------
-- Table structure for xxl_job_user
-- ----------------------------
    IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[xxl_job_user]') AND type IN ('U'))
DROP TABLE [dbo].[xxl_job_user]
    go

CREATE TABLE [dbo].[xxl_job_user] (
    [id] INT NOT NULL PRIMARY KEY IDENTITY(1,1),
    [username] varchar(50)    NOT NULL,
    [password] varchar(50)    NOT NULL,
    [role] int  NOT NULL,
    [permission] varchar(255)    NULL
    )
    go

    -- ----------------------------
-- Records of xxl_job_user
-- ----------------------------
    INSERT INTO [dbo].[xxl_job_user] ( [username], [password], [role], [permission]) VALUES ('admin', 'e10adc3949ba59abbe56e057f20f883e', '1', NULL)
    go

-------------------------------------------------------------
-------------------------------------------------------------










-- ----------------------------
-- Indexes structure for table xxl_job_log
-- ----------------------------
CREATE NONCLUSTERED INDEX [I_trigger_time]
ON [dbo].[xxl_job_log] (
  [trigger_time] ASC
)
;

CREATE NONCLUSTERED INDEX [I_handle_code]
ON [dbo].[xxl_job_log] (
  [handle_code] ASC
)
;



-- ----------------------------
-- Indexes structure for table xxl_job_log_report
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [i_trigger_day]
ON [dbo].[xxl_job_log_report] (
  [trigger_day] ASC
)
;

-- ----------------------------
-- Indexes structure for table xxl_job_log_report
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [i_username]
ON [dbo].[xxl_job_user] (
  [username] ASC
)
;







-- ----------------------------
-- Indexes structure for table xxl_job_registry
-- ----------------------------
CREATE NONCLUSTERED INDEX [i_g_k_v]
ON [dbo].[xxl_job_registry] (
  [registry_group] ASC,
  [registry_key] ASC,
  [registry_value] ASC
)
;

---------
INSERT INTO [dbo].[xxl_job_group] ( app_name, title, address_type, address_list, update_time) VALUES ( 'xxl-job-executor-sample', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
INSERT INTO [dbo].[xxl_job_info]  ( job_group, job_desc, add_time, update_time, author, alarm_email, schedule_type, schedule_conf, misfire_strategy, executor_route_strategy, executor_handler, executor_param, executor_block_strategy, executor_timeout, executor_fail_retry_count, glue_type, glue_source, glue_remark, glue_updatetime, child_jobid) VALUES ( 1, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');


